package com.skywolf.chem.match.common.config;

import com.skywolf.chem.match.utils.RedisUtils;
import groovy.util.logging.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.util.Set;

/**
 * 项目关闭释放分布式锁
 *
 * @Author sj
 * Date on 2021/9/30  10:28
 * @Version 1.0
 */
@Component
@Slf4j
public class RedissonClearLockConfig {


    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @PreDestroy
    public void clearRedissonKey() {
        Set<String> groupLock = redisTemplate.keys("lock:group:*");
        Set<String> orderLock = redisTemplate.keys("order:sn:*");
        if (null != groupLock && groupLock.size() > 0) {
            redisTemplate.delete(groupLock);
        }
        if (null != orderLock && orderLock.size() > 0) {
            redisTemplate.delete(orderLock);
        }
    }
}
